Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storageincentives): storage incentives phase 4 #4345

Merged
merged 10 commits into from
Sep 28, 2023
Merged

Conversation

@zelig zelig added this to the si-phase4 milestone Sep 24, 2023
@zelig zelig self-assigned this Sep 24, 2023
@zelig zelig closed this Sep 24, 2023
@zelig zelig reopened this Sep 24, 2023
@zelig zelig changed the title feat(storageincentives): main feature branch for storage incentives phase 4 feat(storageincentives): storage incentives phase 4 Sep 25, 2023
@istae istae requested review from mrekucci and istae September 25, 2023 11:36
sample, err := a.makeSample(ctx, storageRadius)
if err != nil {
return false, err
}

a.logger.Info("produced sample", "hash", sample.ReserveSampleHash, "radius", sample.StorageRadius, "round", round)

a.state.SetSampleData(round, sample, time.Since(now))
a.state.SetSampleData(round, sample)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was the duration of the sampler removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The makeSample function saves the duration into a.metrics.SampleDuration and on rchash endpoint call, SampleWithProofs calculates the process time. This additional time handling seemed redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the API returns the duration though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current version also returns (storageincentives/agent.go:596)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@istae istae Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the redistributionstate endpoints needs it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see

@nugaon nugaon requested a review from istae September 26, 2023 18:57
@@ -19,8 +19,9 @@ func (s *Service) rchash(w http.ResponseWriter, r *http.Request) {
logger := s.logger.WithName("get_rchash").Build()

paths := struct {
Depth *uint8 `map:"depth" validate:"required"`
Depth uint8 `map:"depth" validate:"min=0"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The min=0 tag is not needed, the 0 is the minimum of an unsigned integer.

@@ -34,7 +35,14 @@ func (s *Service) rchash(w http.ResponseWriter, r *http.Request) {
return
}

resp, err := s.redistributionAgent.SampleWithProofs(r.Context(), anchor1, *paths.Depth)
anchor2, err := hex.DecodeString(paths.Anchor2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to rather register a new pre-map hook (api.go:281):

"decHex": func(v string) (string, error) {
	buf, err := hex.DecodeString(v)
	return string(buf), err
},

Then simply use map:"anchor2,decHex" above and caste []bytes(anchor1) when you want to use it. The same goes for the Anchor1.

pkg/bmt/bmt.go Outdated
@@ -40,6 +40,19 @@ type Hasher struct {
span []byte // The span of the data subsumed under the chunk
}

// facade
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should describe what this function does and should start with the: NewHasher... (by Golang convention).

pkg/bmt/proof.go Outdated
for i := p.size; i < p.maxSize; i += len(zerosection) {
_, err := p.Write(zerosection)
if err != nil {
return []byte{}, err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return nil, err.

return []byte{}, err
}
}
return p.Hasher.Hash(b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stay consistent, return p.Hash(b) will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it calls its ancestor's hash function that contains the logic for the hash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stay consistent, return p.Hash(b) will do.

i dont think so

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're doing the same with p.Write instead of p.Hasher.Write above, which is also Hasher's method. So I'd recommend being consistent.

ChunkAddr string `json:"chunkAddr"`
}

// Transforms arguments to ChunkInclusionProof object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functin description should start with its name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not fixed.

}

// Transforms arguments to ChunkInclusionProof object
func NewChunkInclusionProof(proofp1, proofp2 bmt.Proof, proofp3 bmt.Proof, sampleItem storer.SampleItem) (ChunkInclusionProof, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This proofp1, proofp2 bmt.Proof, proofp3 bmt.Proof can be rewriten as proofp1, proofp2, proofp3 bmt.Proof.

}

// Transforms proof object to its hexadecimal representation
func newHexProofs(proof bmt.Proof) hexProof {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function description should start with its name.


// to generate uploads using the input
// cat socs.txt | tail 19 | head 16 | perl -pne 's/([a-f0-9]+)\t([a-f0-9]+)\t([a-f0-9]+)\t([a-f0-9]+)/echo -n $4 | xxd -r -p | curl -X POST \"http:\/\/localhost:1633\/soc\/$1\/$2?sig=$3\" -H \"accept: application\/json, text\/plain, \/\" -H \"content-type: application\/octet-stream\" -H \"swarm-postage-batch-id: 14b26beca257e763609143c6b04c2c487f01a051798c535c2f542ce75a97c05f\" --data-binary \@-/'
func TestSocMine(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description is vague, so I'm not quite sure why this is necessary. If it exists solely to generate input for the soc endpoint test, then consider generating fixtures and writing a soc test using them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this was meant to utilize the test's output and upload chunks trough the SOC API endpoint.
the test was running in a different environment where this test couldn't be called (no build tools installed etc.)
the comment was made by @zelig . shall we remove?

pkg/storer/sample.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mrekucci mrekucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from some comments, LGTM!

return []byte{}, err
}
}
return p.Hasher.Hash(b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're doing the same with p.Write instead of p.Hasher.Write above, which is also Hasher's method. So I'd recommend being consistent.

}

// Only called by rchash API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method description should start with its name.

ChunkAddr string `json:"chunkAddr"`
}

// Transforms arguments to ChunkInclusionProof object
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not fixed.

@nugaon nugaon merged commit 0890460 into master Sep 28, 2023
@nugaon nugaon deleted the feat/phase4 branch September 28, 2023 11:35
istae added a commit that referenced this pull request Oct 3, 2023
istae added a commit that referenced this pull request Oct 3, 2023
Co-authored-by: Viktor Levente Tóth <[email protected]>
Co-authored-by: nugaon <[email protected]>
Co-authored-by: istae <[email protected]>
mrekucci pushed a commit that referenced this pull request Nov 13, 2023
Co-authored-by: Viktor Levente Tóth <[email protected]>
Co-authored-by: nugaon <[email protected]>
Co-authored-by: istae <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants